package ptij.ADSL.de;

import ptolemy.kernel.util.*;
import ptolemy.actor.*;
import ptolemy.actor.gui.*;
import ptolemy.data.expr.*;
import ptolemy.data.*;
import ptolemy.domains.de.kernel.*;

import ptolemy.domains.de.lib.TimedDelay;

import ptolemy.actor.lib.Clock;
import ptolemy.actor.lib.Ramp;

import ptij.ADSL.de.ATUC.ATUC;
import ptij.ADSL.de.ATUR.ATUR;

import java.io.*;

public class ADSL {
 
    public static void main(String [] arg) throws IllegalActionException,
        NameDuplicationException {

            Workspace w = new Workspace("w");
            TypedCompositeActor _toplevel = new TypedCompositeActor(w);	    
            _toplevel.setName("ADSLSystem");

            DEDirector deDirector = new DEDirector(_toplevel, "deDirector");
	    // deDirector.schedulerType.setToken(new StringToken("srlike"));

	    Manager exec = new Manager(w, "exec");
	    _toplevel.setManager(exec);
	    
            BroadBandNet bnet = new BroadBandNet(_toplevel, "BroadBandNet");
	    bnet.AS0_Rate.setToken(new IntToken(1));
	    bnet.LS0_Rate.setToken(new IntToken(1));
	    
            ATUC atuc = new ATUC(_toplevel, "ATUC");
	    ATUR atur = new ATUR(_toplevel, "ATUR");

            CustomerNet cnet = new CustomerNet(_toplevel, "CustomerNet");
	    cnet.LS0_Rate.setToken(new IntToken(1));
	    
	    TimedDelay d3 = new TimedDelay(_toplevel, "d3");
	    TimedDelay d4 = new TimedDelay(_toplevel, "d4");
	    TimedDelay d5 = new TimedDelay(_toplevel, "d5");	    
	    	    
	    _toplevel.connect(bnet.AS0, atuc.AS0);
	    _toplevel.connect(bnet.LS0, atuc.LS0_in);
	    _toplevel.connect(bnet.dataTx, atuc.dataTx);
	    _toplevel.connect(atuc.LS0_out, d3.input);
	    _toplevel.connect(d3.output, bnet.LS0);
	    
	    _toplevel.connect(atuc.tx, atur.rx);
            _toplevel.connect(atur.tx, atuc.rx);
	    	    
	    _toplevel.connect(atur.AS0, cnet.AS0);
	    _toplevel.connect(atur.LS0_out, cnet.LS0);
	    _toplevel.connect(cnet.LS0, d4.input);
	    _toplevel.connect(d4.output, atur.LS0_in);
	    _toplevel.connect(cnet.dataTx, d5.input);
	    _toplevel.connect(d5.output, atur.dataTx);

            try {
	       deDirector.stopTime.setExpression("20000.0");
               exec.run();
	    }
	    catch(Exception ex) {
	    
	    }
/* 
       try {
	    java.io.FileWriter fw = new java.io.FileWriter(
                _toplevel.getName() + ".xml");
	    _toplevel.exportMoML(fw);
	    fw.close();
	}
	catch(Exception ex) {
	    System.out.println(ex);
        } */
         
    }
}
